public class WaterHeater {
    private State state;

    public WaterHeater() {
        this.state = new StandbyState();
    }

    public void setState(State state) {
        this.state = state;
    }

    public void start() {
        state.start(this);
    }

    public void detect() {
        state.detect(this);
    }

    public void heat() {
        state.heat(this);
    }

    public void powerOff() {
        state.powerOff(this);
    }

    public void repair() {
        state.repair(this);
    }
}

public interface State {
    void start(WaterHeater waterHeater);
    void detect(WaterHeater waterHeater);
    void heat(WaterHeater waterHeater);
    void powerOff(WaterHeater waterHeater);
    void repair(WaterHeater waterHeater);
}

public class StandbyState implements State {
    public void start(WaterHeater waterHeater) {
        System.out.println("Starting...");
        waterHeater.setState(new DetectState());
    }

    public void detect(WaterHeater waterHeater) {
        System.out.println("Cannot detect in standby state.");
    }

    public void heat(WaterHeater waterHeater) {
        System.out.println("Cannot heat in standby state.");
    }

    public void powerOff(WaterHeater waterHeater) {
        System.out.println("Already in standby state.");
    }

    public void repair(WaterHeater waterHeater) {
        System.out.println("Repairing...");
        waterHeater.setState(new RepairState());
    }
}

public class DetectState implements State {
    public void start(WaterHeater waterHeater) {
        System.out.println("Already started.");
    }

    public void detect(WaterHeater waterHeater) {
        System.out.println("Detecting...");
        waterHeater.setState(new HeatState());
    }

    public void heat(WaterHeater waterHeater) {
        System.out.println("Cannot heat in detect state.");
    }

    public void powerOff(WaterHeater waterHeater) {
        System.out.println("Powering off...");
        waterHeater.setState(new StandbyState());
    }

    public void repair(WaterHeater waterHeater) {
        System.out.println("Repairing...");
        waterHeater.setState(new RepairState());
    }
}

public class HeatState implements State {
    public void start(WaterHeater waterHeater) {
        System.out.println("Already started.");
    }

    public void detect(WaterHeater waterHeater) {
        System.out.println("Cannot detect in heat state.");
    }

    public void heat(WaterHeater waterHeater) {
        System.out.println("Heating...");
    }

    public void powerOff(WaterHeater waterHeater) {
        System.out.println("Powering off...");
        waterHeater.setState(new StandbyState());
    }

    public void repair(WaterHeater waterHeater) {
        System.out.println("Repairing...");
        waterHeater.setState(new RepairState());
    }
}

public class RepairState implements State {
    public void start(WaterHeater waterHeater) {
        System.out.println("Cannot start in repair state.");
    }

    public void detect(WaterHeater waterHeater) {
        System.out.println("Cannot detect in repair state.");
    }

    public void heat(WaterHeater waterHeater) {
        System.out.println("Cannot heat in repair state.");
    }

    public void powerOff(WaterHeater waterHeater) {
        System.out.println("Powering off...");
        waterHeater.setState(new StandbyState());
    }

    public void repair(WaterHeater waterHeater) {
        System.out.println("Already in repair state.");
    }
}